package com.walkline.travelassistant.dao;

import java.util.Vector;

import org.json.me.JSONObject;

import com.walkline.travelassistant.TravelAssistantException;
import com.walkline.travelassistant.TravelAssistantSDK;
import com.walkline.travelassistant.inf.Scheme;
import com.walkline.travelassistant.inf.Step;
import com.walkline.travelassistant.inf.StepWrapper;
import com.walkline.util.Function;

public class TravelAssistantScheme extends TravelAssistantObject implements Scheme
{
	private int _distance = 0;
	private String _distance_str = "";
	private StepWrapper _steps = null;
	private String _scheme_name = "";

	public TravelAssistantScheme(TravelAssistantSDK travelAssistant, JSONObject jsonObject) throws TravelAssistantException
	{
		super(travelAssistant, jsonObject);

		JSONObject schemeObject = jsonObject;
		if (schemeObject != null)
		{
			_distance = schemeObject.optInt("distance");
			_distance_str = Function.convertDistance2String(_distance);
			_steps = new TravelAssistantStepWrapper(travelAssistant, schemeObject);

			Step step;
			Vector steps = _steps.getSteps();
			StringBuffer sb = new StringBuffer();
			for (int i=0; i<steps.size(); i++)
			{
				step = (Step) steps.elementAt(i);
				if (step.getSchemeName() != null)
				{
					sb.append(step.getSchemeName()).append(" → ");
					//_scheme_name = step.getSchemeName();
					//break;
				}
			}
			_scheme_name = sb.toString();
			if (_scheme_name.endsWith(" → ")) {_scheme_name = _scheme_name.substring(0, _scheme_name.length() - 3);}
		}
	}

	public int getDistance() {return _distance;}

	public String getDistanceStr() {return _distance_str;}

	public StepWrapper getSteps() {return _steps;}

	public String getSchemeName() {return _scheme_name;}
}